package com.ddd.interfaces.controller.user;


import com.ddd.domain.user.dto.UserDto;
import com.ddd.domain.user.entity.UserDo;
import com.ddd.domain.user.service.UserService;
import com.ddd.infrastructure.common.Result;
import com.ddd.infrastructure.utils.BeanCopierUtil;
import com.ddd.infrastructure.utils.ResultUtil;
import com.ddd.interfaces.vo.user.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {


    //http://localhost:7101/user/getUserAll

    @Autowired
    private UserService userService;
    @GetMapping("/getUserAll")
    public Result<List<UserVo>> getUserAll(){
        List<UserDto> userAll = userService.getUserAll();
        log.info("getUserAll:",userAll);
        return ResultUtil.success(BeanCopierUtil.copylist(userAll,UserVo.class));
    }

    //http://localhost:7101/user/addByUser

    /*
  {

            "name": "demoData",
            "pass": "demoData",
            "age": 20,
            "sex": "demoData",
            "address": "demoData",
            "phone": "demoData"
    }
    * */
    @PostMapping("/addByUser")
    public Result<Long> addByUser(@RequestBody  UserDo userDo){
        log.info("addByUser:",userDo);
        return  ResultUtil.success(userService.addByUser(userDo));

    }
}
